// StudentController.java
@RestController
@RequestMapping("/api/student")
public class StudentController {
    @Autowired
    private EnrollmentService enrollmentService;

    // 学生选课接口
    @PostMapping("/enroll")
    public ResponseEntity<?> enrollCourse(@RequestParam Integer courseId, 
                                          @AuthenticationPrincipal User user) {
        try {
            enrollmentService.enrollCourse(user.getId(), courseId);
            return ResponseEntity.ok("选课成功");
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    // 查询已选课程
    @GetMapping("/courses")
    public List<Course> getEnrolledCourses(@AuthenticationPrincipal User user) {
        return enrollmentService.getCoursesByStudentId(user.getId());
    }
}